var express = require('express');
const Result = require('../lib/Result');
const isRule = require('../util/isRule');
const Notice = require('../db/models/notice/notice');
var router = express.Router();
/**
 * 获取广告列表,150,149,172
 */
router.get("/:page",(req,res)=>{
    let token = req.auth
    if (isRule(token.rule, [150,149,172], res, token.super)) {
        let page=req.params.page
        let limit=req.query.limit
        Notice.getNoticeList(page,limit).then(value=>{
            res.json(Result.success(value))
        })
    }
})
/**
 * 添加广告,151,149,172
 */
router.post("",(req,res)=>{
    let token = req.auth
    if (isRule(token.rule, [151,149,172], res, token.super)) {
        Notice.addNotice(req.body).then(value=>{
            res.json(Result.success(value))
        })
    }
})
/**
 * 删除广告,153,149,172
 */
router.post("/:id/delete",(req,res)=>{
    let token = req.auth
    if (isRule(token.rule, [153,149,172], res, token.super)) {
        Notice.deldetNotice(req.params.id).then(value=>{
            res.json(Result.success(true))
        })
    }
})
/**
 * 修改广告,152,149,172
 */
router.post("/:id",(req,res)=>{
    let token = req.auth
    if (isRule(token.rule, [152,149,172], res, token.super)) {
        Notice.updateNotice(req.body,req.params.id).then(value=>{
            res.json(Result.success(true))
        })
    }
})
module.exports=router